package com.xiaowan.common.utils;

import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {

    public static String encrptyPwd(String pwd) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        BASE64Encoder base64 = new BASE64Encoder();
        String result = base64.encode(md5.digest(pwd.getBytes("utf-8")));
        return result;
    }

    public static Boolean checkPwd(String inputPwd,String dbPwd) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        if(encrptyPwd(inputPwd).equals(dbPwd)){
            return true;
        }
        return false;
    }
}
